<template>
  <div class="allpage">
    <div class="one">
      <p>编辑资料</p>
    </div>
    <div class="two">
      <div class="file1">
        <input type="file" @change="change($event)" id="touxiang1" />
        <label for="touxiang1" :class="touxiang"
          ><img :src="dizhi" alt=""
        /></label>
      </div>
      <p class="nicheng">{{ nicheng }}</p>
      <div class="sex">
        <span>性别:</span>
        <el-radio v-model="radio" label="1" class="choose">男</el-radio>
        <el-radio v-model="radio" label="2" class="choose">女</el-radio>
      </div>
      <div class="xiugainicheng">
        <span>昵称：</span>
        <input
          type="text"
          :value="nicheng"
          class="xiugai"
          @input="changenicheng"
        />
      </div>
      <div class="shengri">
        <div class="block">
          <span>生日:</span>
          <el-date-picker
            v-model="value1"
            type="date"
            placeholder="选择日期"
            class="xuanzeriqi"
          >
          </el-date-picker>
        </div>
      </div>
      <div class="qq">
        <span>QQ:</span>
        <input type="text" />
      </div>
      <div class="qianming">
        <span>个性签名:</span>

        <input type="textarea" class="xiugaiqianming" :value="qianming" @input="xiugaiqianming" />
      </div>
      <div class="save" @click="upload">保存</div>
    </div>
  </div>
</template>
<script>
import axios from "axios";
export default {
  data() {
    return {
      radio: "1",
      pickerOptions: {
        disabledDate(time) {
          return time.getTime() > Date.now();
        },
      },
      value1: "",
      value2: "",
      textarea: "",
      dizhi: "",
      nicheng: "",
      qianming: "",
    };
  },
  methods: {
    change:async function (e) {
      console.log(e.target.files[0]);
      let objectURL = URL.createObjectURL(e.target.files[0]);
       this.dizhi = objectURL
    },
    changenicheng: function (e) {
      this.nicheng = e.target.value;
    },
    upload: async function () {
      var url = window.location.search.split("?")[1].split("=")[1];
      var formdata1 = new FormData();
      formdata1.append("name", this.$data.nicheng);
      formdata1.append("qianming", this.$data.qianming);
      formdata1.append("dizhi", touxiang1.files[0]);
      formdata1.append("phone",url)
      let msg = await axios.post("/login1/xiugaixinxi",formdata1);
      console.log(msg);
      alert("修改成功")
      window.location.href=`http://localhost:8080/gerenzhuye?phone=${url}`
    },
    xiugaiqianming:function(e){
      this.$data.qianming = e.target.value
    }
  },
  async mounted() {
    var url1 = window.location.search;
    if (url1) {
      let url = window.location.search.split("?")[1].split("=")[1];
      let msg = await axios("/login1/gerenxinxi", { params: { url } });
      let gerenxinxi = msg.data[0];
      this.nicheng = gerenxinxi.name;
      this.xuehao = gerenxinxi.xuehao;
      this.dizhi = gerenxinxi.touxiang;
      this.qianming = gerenxinxi.qianming;
    }
  },
};
</script>
<style lang="scss" scoped>
* {
  margin: 0 auto;
}
.allpage {
  background-color: #f6f8fa;
}
.one {
  width: 60%;
  margin: 0 auto;
  box-sizing: border-box;
  padding-top: 40px;
  position: relative;
}
.one p {
  display: inline;
  padding: 15px 20px;
  background-color: white;
  color: skyblue;
  font-size: 20px;
}
.one p::after {
  content: "";
  display: inline-block;
  position: absolute;
  top: 26px;
  left: 100px;
  z-index: 999;
  width: 0;
  height: 0;
  border: 20px solid white;
  border-top: 20px solid #f6f8fa;
  border-right: 20px solid #f6f8fa;
}
.two {
  width: 60%;
  height: 729px;
  box-sizing: border-box;
  margin: 0 auto;
  background-color: white;
}
.two .file1 input {
  width: 120px;
  height: 120px;
  border-radius: 60px;
  overflow: hidden;
  display: none;
}

.two .file1 img {
  width: 120px;
  height: 120px;
  border-radius: 60px;
  overflow: hidden;
  position: relative;
  left: 45%;
  top: 40px;
}
.two span {
  font-size: 16px;
  color: #87959f;
}
.two input {
  border: 1px solid #dcdfe6;
}

.two .choose {
  margin-left: 30px;
}
.two .nicheng {
  width: 50%;
  height: 20px;
  margin: 0 auto;
  text-align: center;
  margin-top: 60px;
  font-size: 20px;
}
.two .sex {
  width: 50%;
  margin: 0 auto;
  margin-top: 30px;
  margin-left: 35%;
}
.two .xiugainicheng {
  width: 50%;
  margin: 0 auto;
  margin-top: 30px;
  line-height: 44px;
  margin-left: 35%;
}
.two .xiugainicheng span {
  line-height: 44px;
}
.two .xiugainicheng .xiugai {
  margin-left: 20px;
  height: 40px;
  font-size: 24px;
  width: 50%;
}
.two .xiugainicheng .xiugai:focus {
  outline: none;
  border: 1px solid #409eff;
}
.two .shengri {
  width: 50%;
  margin: 0 auto;
  margin-top: 30px;
  margin-left: 35%;
}
.two .shengri .xuanzeriqi {
  margin-left: 32px;
  width: 51%;
  font-size: 20px;
}
.two .qq {
  width: 50%;
  margin: 0 auto;
  margin-top: 30px;
  margin-left: 35%;
}
.two .qq input {
  width: 50%;
  height: 40px;
  margin-left: 40px;
  font-size: 20px;
}
.two .qq input:focus {
  outline: none;
  border: 1px solid #409eff;
}
.two .qianming {
  width: 50%;
  margin: 0 auto;
  margin-top: 30px;
  margin-left: 35%;
}
.two .qianming .xiugaiqianming {
  width: 51%;
  font-size: 20px;
}
.two .qianming span {
  position: relative;
  top: 0;
  left: -35px;
  font-size: 16px;
}
.two .save {
  width: 40%;
  height: 60px;
  margin: 0 auto;
  text-align: center;
  margin-top: 30px;
  background-color: #027cdb;
  font-size: 20px;
  line-height: 60px;
}
</style>